package com.example.validatestudy.demos.tread.sync;

public class SynchronizedTest03 {
    /**
     * synchronized
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("----synchronized修饰方法 ：两个线程同时执行------");
        printTest();
    }

    public static void printTest(){
        Runnable r1 = ()-> new SynchronizedTest03().print(10);
        Runnable r2 = ()-> new SynchronizedTest03().print(10);
        new Thread(r1).start();
        new Thread(r2).start();
    }

    public synchronized void print(int total){
        while (0 < total){
            System.out.println(Thread.currentThread().getName()+ "-print():" + total--);
        }
    }

}
